﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Bit.Art.Api.Controllers
{
    public class BaseController : Controller
    {
        public uint? _uid;

        protected uint LoginUid => GetLogonUid();
        
        private uint GetLogonUid()
        {
#if UNITTEST
            if (_uid.HasValue)
                return _uid.Value;
#endif
            var items = from c in User.Claims select new { c.Type, c.Value };
            var subClaim = User.Claims.Single(c => string.Compare(c.Type, "sub", true) == 0);
            var subValue = subClaim.Value;
            var uid = uint.Parse(subValue);
            return uid;
        }
    }
}